﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace CNDM.Ajax
{
    public partial class newslist : System.Web.UI.Page
    {
        private string cat_id = "";
        private int pageindex = 1;
        private int pagesize = 10;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["cat_id"] != null && Request.QueryString["cat_id"].ToString() != "")
            {
                cat_id = Request.QueryString["cat_id"].ToString();
            }

            if (Request.QueryString["pageindex"] != null && Request.QueryString["pageindex"].ToString() != "")
            {
                pageindex = Convert.ToInt32(Request.QueryString["pageindex"].ToString());
            }

            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            DataTable dtList = new DataTable();
            dtList = BO.News.NewsData.Get_DanhSachTin("0", cat_id, pageindex, pagesize);
            repList.DataSource = dtList;
            repList.DataBind();
        }

        protected void repList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Image imgNews = (Image)e.Item.FindControl("imgNews");
                if (DataBinder.Eval(e.Item.DataItem, "News_Image").ToString().Trim() == "")
                {
                    imgNews.Visible = false;
                }
                else
                {
                    imgNews.Visible = true;
                    imgNews.ImageUrl = DataBinder.Eval(e.Item.DataItem, "Image_Url").ToString();
                }


            }
        }
    }
}